<?php
  include "./include/om_config.inc";
  $smarty = new smartyWWW();
  $msg = "";

  $selectMcxQueryResult = mysql_query("SELECT DISTINCT(expiryDate),expiryDateBc FROM bhavcopy WHERE TRIM(contractCode) LIKE 'GOLD' ORDER BY expiryDate");
  while($row = mysql_fetch_array($selectMcxQueryResult))
  {
    $dbExpiryDate = mktime(0,0,0,substr($row['expiryDate'],5,2),substr($row['expiryDate'],8,2),substr($row['expiryDate'],0,4));
    $currentDate  = mktime(0,0,0,date("m"),date("d"),date("y"));
    if($dbExpiryDate > $currentDate)
      $goldItem[] = $row;
  }
  $selectMcxQueryResult = mysql_query("SELECT DISTINCT(expiryDate),expiryDateBc FROM bhavcopy WHERE TRIM(contractCode) LIKE 'SILVER' ORDER BY expiryDate");
  while($row = mysql_fetch_array($selectMcxQueryResult))
  {
    $dbExpiryDate = mktime(0,0,0,substr($row['expiryDate'],5,2),substr($row['expiryDate'],8,2),substr($row['expiryDate'],0,4));
    $currentDate  = mktime(0,0,0,date("m"),date("d"),date("y"));
    if($dbExpiryDate > $currentDate)
      $silverItem[] = $row;
  }
  $selectMcxQueryResult = mysql_query("SELECT DISTINCT(expiryDate),expiryDateBc FROM bhavcopy WHERE TRIM(contractCode) LIKE 'COPPER' ORDER BY expiryDate");
  while($row = mysql_fetch_array($selectMcxQueryResult))
  {
    $dbExpiryDate = mktime(0,0,0,substr($row['expiryDate'],5,2),substr($row['expiryDate'],8,2),substr($row['expiryDate'],0,4));
    $currentDate  = mktime(0,0,0,date("m"),date("d"),date("y"));
    if($dbExpiryDate > $currentDate)
      $copperItem[] = $row;
  }
  $selectMcxQueryResult = mysql_query("SELECT DISTINCT(expiryDate),expiryDateBc FROM bhavcopy WHERE TRIM(contractCode) LIKE 'CRUDEOIL' ORDER BY expiryDate");
  while($row = mysql_fetch_array($selectMcxQueryResult))
  {
    $dbExpiryDate = mktime(0,0,0,substr($row['expiryDate'],5,2),substr($row['expiryDate'],8,2),substr($row['expiryDate'],0,4));
    $currentDate  = mktime(0,0,0,date("m"),date("d"),date("y"));
    if($dbExpiryDate > $currentDate)
      $crudeoilItem[] = $row;
  }
  $selectMcxQueryResult = mysql_query("SELECT DISTINCT(expiryDate),expiryDateBc FROM bhavcopy WHERE TRIM(contractCode) LIKE 'ZINC' ORDER BY expiryDate");
  while($row = mysql_fetch_array($selectMcxQueryResult))
  {
    $dbExpiryDate = mktime(0,0,0,substr($row['expiryDate'],5,2),substr($row['expiryDate'],8,2),substr($row['expiryDate'],0,4));
    $currentDate  = mktime(0,0,0,date("m"),date("d"),date("y"));
    if($dbExpiryDate > $currentDate)
      $zincItem[] = $row;
  }
  $selectMcxQueryResult = mysql_query("SELECT DISTINCT(expiryDate),expiryDateBc FROM bhavcopy WHERE TRIM(contractCode) LIKE 'LEAD' ORDER BY expiryDate");
  while($row = mysql_fetch_array($selectMcxQueryResult))
  {
    $dbExpiryDate = mktime(0,0,0,substr($row['expiryDate'],5,2),substr($row['expiryDate'],8,2),substr($row['expiryDate'],0,4));
    $currentDate  = mktime(0,0,0,date("m"),date("d"),date("y"));
    if($dbExpiryDate > $currentDate)
      $leadItem[] = $row;
  }
  $selectMcxQueryResult = mysql_query("SELECT DISTINCT(expiryDate),expiryDateBc FROM bhavcopy WHERE TRIM(contractCode) LIKE 'NICKEL' ORDER BY expiryDate");
  while($row = mysql_fetch_array($selectMcxQueryResult))
  {
    $dbExpiryDate = mktime(0,0,0,substr($row['expiryDate'],5,2),substr($row['expiryDate'],8,2),substr($row['expiryDate'],0,4));
    $currentDate  = mktime(0,0,0,date("m"),date("d"),date("y"));
    if($dbExpiryDate > $currentDate)
      $nickelItem[] = $row;
  }
  $selectMcxQueryResult = mysql_query("SELECT DISTINCT(expiryDate),expiryDateBc FROM bhavcopy WHERE TRIM(contractCode) LIKE 'NATURALGAS' ORDER BY expiryDate");
  while($row = mysql_fetch_array($selectMcxQueryResult))
  {
    $dbExpiryDate = mktime(0,0,0,substr($row['expiryDate'],5,2),substr($row['expiryDate'],8,2),substr($row['expiryDate'],0,4));
    $currentDate  = mktime(0,0,0,date("m"),date("d"),date("y"));
    if($dbExpiryDate > $currentDate)
      $naturalgasItem[] = $row;
  }

  $selectNiftyQueryResult = mysql_query("SELECT DISTINCT(expiryDate),expiryDateBc FROM bhavcopyf_o WHERE TRIM(contractCode) LIKE 'NIFTY' ORDER BY expiryDate");
  while($row = mysql_fetch_array($selectNiftyQueryResult))
  {
    $dbExpiryDate = mktime(0,0,0,substr($row['expiryDate'],5,2),substr($row['expiryDate'],8,2),substr($row['expiryDate'],0,4));
    $currentDate  = mktime(0,0,0,date("m"),date("d"),date("y"));
    if($dbExpiryDate > $currentDate)
      $foNItem[] = $row;
  }
  $selectBNQueryResult = mysql_query("SELECT DISTINCT(expiryDate),expiryDateBc FROM bhavcopyf_o WHERE TRIM(contractCode) LIKE 'BANKNIFTY' ORDER BY expiryDate");
  while($row = mysql_fetch_array($selectBNQueryResult))
  {
    $dbExpiryDate = mktime(0,0,0,substr($row['expiryDate'],5,2),substr($row['expiryDate'],8,2),substr($row['expiryDate'],0,4));
    $currentDate  = mktime(0,0,0,date("m"),date("d"),date("y"));
    if($dbExpiryDate > $currentDate)
      $foBNItem[] = $row;
  }

//  echo "<pre>";
//  print_r($silverItem);
  //9909024045 :hitesh call for expirydate
  $smarty->assign("goldItem",$goldItem);
  $smarty->assign("silverItem",$silverItem);
  $smarty->assign("copperItem",$copperItem);
  $smarty->assign("crudeoilItem",$crudeoilItem);
  $smarty->assign("zincItem",$zincItem);
  $smarty->assign("leadItem",$leadItem);
  $smarty->assign("nickelItem",$nickelItem);
  $smarty->assign("naturalgasItem",$naturalgasItem);
  $smarty->assign("foNItem",$foNItem);
  $smarty->assign("foBNItem",$foBNItem);
  $smarty->display("setPrint.tpl");
?>